<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div1 {
            width: 200px;
            height: 200px;
            background-color: red;
        }

        .div2 {
            width: 300px;
            height: 300px;
            /* background-color: blue; */
            border: 1px solid black;
            /* 相对定位 */
            position: relative;
        }

        .div2 .son {
            width: 100px;
            height: 100px;
            background-color: blue;
            /* 绝对定位 */
            position: absolute;
            /* top: 20px;
            left: 20px; */
            /* 水平方向居中 */
            left: 50%;
            margin-left: -50px;
            /* 垂直方向居中 */
            top: 50%;
            margin-top: -50px;
        }
        .div3 {
            width: 200px;
            height: 200px;
            background-color: green;
        }
    </style>
</head>

<body>
    <div class="div1"></div>
    <div class="div2">
        <div class="son"></div>
    </div>
    <div class="div3"></div>
</body>

</html>